home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / amiga_draw.s < prev    next >
Text File  |  1998-03-01  |  39KB  |  1,782 lines

  1. *
  2. *       amiga_draw.s - optimized rendering
  3. *       by Aki Laukkanen <amlaukka@cc.helsinki.fi>
  4. *
  5. *       This file is public domain.
  6. *
  7.  
  8.         mc68020
  9.  
  10.         include "exec/types.i"
  11.         include "exec/funcdef.i"
  12.         include "exec/exec_lib.i"
  13.  
  14. ;-----------------------------------------------------------------------
  15.  
  16. SCREENWIDTH    equ    320
  17.  
  18. FRACBITS    equ    16
  19. FRACUNIT    equ    (1<<FRACBITS)
  20.  
  21. *
  22. *       global functions
  23. *
  24.  
  25.         xdef    _init_r_draw
  26.         xdef    @init_r_draw
  27.  
  28. ;;        xdef    _R_DrawColumn_030            ; high detail
  29. ;;        xdef    @R_DrawColumn_030
  30.         xdef    _R_DrawColumn_040            ; high detail
  31.         xdef    @R_DrawColumn_040
  32.         xdef    _R_DrawSpan_040
  33.         xdef    @R_DrawSpan_040
  34.         xdef    _R_DrawColumn_060
  35.         xdef    @R_DrawColumn_060
  36.         xdef    _R_DrawSpan_060
  37.         xdef    @R_DrawSpan_060
  38.         xdef    _R_DrawFuzzColumn
  39.         xdef    @R_DrawFuzzColumn
  40. ;;        xdef    _R_DrawTranslatedColumn
  41. ;;        xdef    @R_DrawTranslatedColumn
  42.  
  43.         xdef    _R_DrawSpanLow                ; low detail
  44.         xdef    @R_DrawSpanLow
  45.         xdef    _R_DrawColumnLow
  46.         xdef    @R_DrawColumnLow
  47.         xdef    _R_DrawFuzzColumnLow
  48.         xdef    @R_DrawFuzzColumnLow
  49. ;;        xdef    _R_DrawTranslatedColumnLow
  50. ;;        xdef    @R_DrawTranslatedColumnLow
  51.  
  52.         xdef    _R_DrawMaskedColumn
  53.         xdef    @R_DrawMaskedColumn
  54.  
  55.         xdef    _V_DrawPatch
  56.         xdef    @V_DrawPatch
  57.         xdef    _V_DrawPatchDirect
  58.         xdef    @V_DrawPatchDirect
  59.  
  60. *
  61. *       needed symbols/labels
  62. *
  63.  
  64.         xref    _SysBase
  65.         xref    _SCREENWIDTH
  66.         xref    _SCREENHEIGHT
  67.         xref    _dc_yl
  68.         xref    _dc_yh
  69.         xref    _dc_x
  70.         xref    _columnofs
  71. ;;        xref    _ylookup
  72.         xref    _ylookup2
  73.         xref    _dc_iscale
  74.         xref    _centery
  75.         xref    _dc_texturemid
  76.         xref    _dc_source
  77.         xref    _dc_colormap
  78.         xref    _ds_xfrac
  79.         xref    _ds_yfrac
  80.         xref    _ds_x1
  81.         xref    _ds_y
  82.         xref    _ds_x2
  83.         xref    _ds_xstep
  84.         xref    _ds_ystep
  85.         xref    _ds_source
  86.         xref    _ds_colormap
  87.         xref    _fuzzoffset
  88.         xref    _fuzzpos
  89.         xref    _viewheight
  90.         xref    _dc_translation
  91.         xref    _colormaps
  92.  
  93. ;-----------------------------------------------------------------------
  94.         section    text,code
  95.  
  96.         near    a4,-2
  97.  
  98. ; low detail drawing functions
  99.  
  100. ;-----------------------------------------------------------------------
  101. ; patch _SCREENWIDTH into draw routines (self-modifying code) and flush caches
  102.  
  103. _init_r_draw
  104. @init_r_draw
  105.         movem.l    a6,-(sp)
  106.  
  107.         lea    @init_r_draw(pc),a0
  108.  
  109.         move.l    _SCREENWIDTH(a4),d0    ; d0 = _SCREENWIDTH
  110.  
  111.         move.w    d0,sw12_1-@init_r_draw+2(a0)
  112.         move.w    d0,sw12_3-@init_r_draw+2(a0)
  113.         move.w    d0,sw12_4-@init_r_draw+2(a0)
  114.         move.w    d0,sw12_4a-@init_r_draw+2(a0)
  115.         move.w    d0,sw12_5-@init_r_draw+2(a0)
  116.         move.w    d0,sw12_5a-@init_r_draw+2(a0)
  117.         move.w    d0,sw12_6-@init_r_draw+2(a0)
  118.         move.w    d0,sw12_7-@init_r_draw+2(a0)
  119.         move.w    d0,sw12_8-@init_r_draw+2(a0)
  120.  
  121.         add.l    d0,d0            ; d0 = 2 * _SCREENWIDTH
  122.  
  123.         move.w    d0,sw22_1-@init_r_draw+2(a0)
  124.         move.w    d0,sw22_3-@init_r_draw+2(a0)
  125.         move.w    d0,sw22_4-@init_r_draw+2(a0)
  126.         move.w    d0,sw22_4a-@init_r_draw+2(a0)
  127.         move.w    d0,sw22_5-@init_r_draw+2(a0)
  128.         move.w    d0,sw22_5a-@init_r_draw+2(a0)
  129.         move.w    d0,sw22_6-@init_r_draw+2(a0)
  130.         move.w    d0,sw22_7-@init_r_draw+2(a0)
  131.         move.w    d0,sw22_8-@init_r_draw+2(a0)
  132.  
  133.         add.l    _SCREENWIDTH(a4),d0    ; d0 = 3 * _SCREENWIDTH
  134.  
  135.         move.w    d0,sw32_1-@init_r_draw+2(a0)
  136.         move.w    d0,sw32_3-@init_r_draw+2(a0)
  137.         move.w    d0,sw32_4-@init_r_draw+2(a0)
  138.         move.w    d0,sw32_4a-@init_r_draw+2(a0)
  139.         move.w    d0,sw32_5-@init_r_draw+2(a0)
  140.         move.w    d0,sw32_5a-@init_r_draw+2(a0)
  141.         move.w    d0,sw32_6-@init_r_draw+2(a0)
  142.         move.w    d0,sw32_7-@init_r_draw+2(a0)
  143.         move.w    d0,sw32_8-@init_r_draw+2(a0)
  144.  
  145.         add.l    _SCREENWIDTH(a4),d0    ; d0 = 4 * _SCREENWIDTH
  146.  
  147.         move.w    d0,sw42_1-@init_r_draw+2(a0)
  148.         move.w    d0,sw42_3-@init_r_draw+2(a0)
  149.         move.w    d0,sw42_4-@init_r_draw+2(a0)
  150.         move.w    d0,sw42_5-@init_r_draw+2(a0)
  151.         move.w    d0,sw42_6-@init_r_draw+2(a0)
  152.         move.w    d0,sw42_8-@init_r_draw+2(a0)
  153.  
  154.         move.l    _SCREENWIDTH(a4),d0
  155.         neg.l    d0            ; d0 = -_SCREENWIDTH
  156.  
  157.         move.w    d0,swm10_1-@init_r_draw(a0)
  158.         move.w    d0,swm10_3-@init_r_draw(a0)
  159.         move.w    d0,swm10_4-@init_r_draw(a0)
  160.         move.w    d0,swm10_5-@init_r_draw(a0)
  161.         move.w    d0,swm10_6-@init_r_draw(a0)
  162.         move.w    d0,swm10_8-@init_r_draw(a0)
  163.  
  164.         add.l    d0,d0            ; d0 = -2*_SCREENWIDTH
  165.  
  166.         move.w    d0,swm20_1-@init_r_draw(a0)
  167.         move.w    d0,swm20_3-@init_r_draw(a0)
  168.         move.w    d0,swm20_4-@init_r_draw(a0)
  169.         move.w    d0,swm20_5-@init_r_draw(a0)
  170.         move.w    d0,swm20_6-@init_r_draw(a0)
  171.         move.w    d0,swm20_8-@init_r_draw(a0)
  172.  
  173.         sub.l    _SCREENWIDTH(a4),d0    ; d0 = -3*_SCREENWIDTH
  174.  
  175.         move.w    d0,swm30_1-@init_r_draw(a0)
  176.         move.w    d0,swm30_3-@init_r_draw(a0)
  177.         move.w    d0,swm30_4-@init_r_draw(a0)
  178.         move.w    d0,swm30_5-@init_r_draw(a0)
  179.         move.w    d0,swm30_6-@init_r_draw(a0)
  180.         move.w    d0,swm30_8-@init_r_draw(a0)
  181.  
  182.         movea.l    _SysBase(a4),a6
  183.         jsr    _LVOCacheClearU(a6)
  184.  
  185.         movem.l    (sp)+,a6
  186.         rts
  187.  
  188. ;-----------------------------------------------------------------------
  189.         cnop    0,4
  190.  
  191. _R_DrawColumnLow
  192. @R_DrawColumnLow
  193.         movem.l d3-d4/d6-d7/a2/a3,-(sp)
  194.  
  195.         move.l  _dc_yh(a4),d7    ; count = _dc_yh - _dc_yl
  196.         move.l  _dc_yl(a4),d0
  197.         sub.l   d0,d7
  198.         bmi.w   l.end1
  199.  
  200.         move.l  _dc_x(a4),d1    ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  201.         movea.l    _ylookup2(a4),a0 ;     = ylookup2[_dc_yl] + (_dc_x<<1)
  202.         add.l    d1,d1        ; dc_x <<= 1 
  203.         move.l  (a0,d0.l*4),a0
  204.         adda.l    d1,a0
  205.  
  206.         move.l  _dc_colormap(a4),d4
  207.         move.l  _dc_source(a4),a1
  208.  
  209.         move.l  _dc_iscale(a4),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  210.         sub.l   _centery(a4),d0
  211.         muls.l  d1,d0
  212.         add.l   _dc_texturemid(a4),d0
  213.  
  214.         moveq   #$7f,d3
  215. sw42_1        lea     (SCREENWIDTH*4).w,a3
  216.  
  217. ; d7: cnt >> 2
  218. ; a0: chunky
  219. ; a1: texture
  220. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  221. ; d1: dfrac (.......................................)
  222. ; d3: $7f
  223. ; d4: light table aligned to 256 byte boundary
  224. ; a3: SCREENWIDTH
  225.  
  226.         move.l  d7,d6
  227.         and.w   #3,d6
  228.  
  229.         swap    d0              ; swap decimals and fraction
  230.         swap    d1
  231.  
  232.         add.w   l.width_tab1(pc,d6.w*2),a0
  233.         lsr.w   #2,d7
  234.         move.w  l.tmap_tab1(pc,d6.w*2),d6
  235.  
  236.         and.w   d3,d0
  237.         sub.w   d1,d0
  238.         add.l   d1,d0           ; setup the X flag
  239.  
  240.         jmp     l.loop1(pc,d6.w)
  241.  
  242.         cnop    0,4
  243. l.width_tab1
  244. swm30_1        dc.w    -3*SCREENWIDTH
  245. swm20_1        dc.w    -2*SCREENWIDTH
  246. swm10_1        dc.w    -1*SCREENWIDTH
  247.         dc.w    0
  248. l.tmap_tab1
  249.         dc.w    l.01-l.loop1
  250.         dc.w    l.11-l.loop1
  251.         dc.w    l.21-l.loop1
  252.         dc.w    l.31-l.loop1
  253. l.loop1
  254. l.31
  255.         move.b  (a1,d0.w),d4
  256.         addx.l  d1,d0
  257.         move.l  d4,a2
  258.         move.w  (a2),d6
  259.         and.w   d3,d0
  260.         move.b    (a2),d6
  261.         move.w    d6,(a0)
  262. l.21
  263.         move.b  (a1,d0.w),d4
  264.         addx.l  d1,d0
  265.         move.l  d4,a2
  266.         move.w  (a2),d6
  267.         and.w   d3,d0
  268.         move.b    (a2),d6
  269. sw12_1        move.w    d6,SCREENWIDTH(a0)
  270. l.11
  271.         move.b  (a1,d0.w),d4
  272.         addx.l  d1,d0
  273.         move.l  d4,a2
  274.         move.w  (a2),d6
  275.         and.w   d3,d0
  276.         move.b    (a2),d6
  277. sw22_1        move.w    d6,SCREENWIDTH*2(a0)
  278. l.01
  279.         move.b  (a1,d0.w),d4
  280.         addx.l  d1,d0
  281.         move.l  d4,a2
  282.         move.w    (a2),d6
  283.         and.w   d3,d0
  284.         move.b  (a2),d6
  285. sw32_1        move.w    d6,SCREENWIDTH*3(a0)
  286.  
  287.         add.l   a3,a0
  288. l.loop_end1
  289.         dbf     d7,l.loop1
  290. l.end1
  291.         movem.l (sp)+,d3-d4/d6-d7/a2/a3
  292.         rts
  293.  
  294. ;-----------------------------------------------------------------------
  295.         cnop    0,4
  296.  
  297. _R_DrawSpanLow
  298. @R_DrawSpanLow
  299.         movem.l d2-d7/a2-a4,-(sp)
  300.         move.l  _ds_y(a4),d0
  301.         move.l  _ds_x1(a4),d1    ; dest = ylookup[_ds_y] + columnofs[_ds_x1]
  302.         movea.l    _ylookup2(a4),a0 ;     = ylookup2[_ds_y] + _ds_x
  303.         add.l    d1,d1
  304.         move.l  (a0,d0.l*4),a0
  305.         adda.l    d1,a0
  306.         move.l  _ds_x2(a4),d7    ; count = _ds_x2 - _ds_x1
  307.         move.l  _ds_source(a4),a1
  308.         add.l    d7,d7
  309.         move.l  _ds_colormap(a4),a2
  310.         sub.l   d1,d7
  311.         addq.l    #2,d7
  312.         move.l  _ds_xfrac(a4),d0
  313.         move.l  _ds_yfrac(a4),d1
  314.         move.l  _ds_xstep(a4),d2
  315.         move.l  _ds_ystep(a4),d3
  316.         move.l  a0,d4        ; notice, that this address must already be aligned by word
  317.         btst    #1,d4
  318.         beq.b   l.skips2
  319.         move.l  d0,d5           ; do the unaligned pixels
  320.         move.l  d1,d6           ; so we can write to longword
  321.         swap    d5              ; boundary in the main loop
  322.         swap    d6
  323.         and.w   #$3f,d5
  324.         and.w   #$3f,d6        ; this is the worst possible
  325.         lsl.w   #6,d6        ; way but hey, this is not a loop
  326.         or.w    d5,d6
  327.         move.b  (a1,d6.w),d5
  328.         add.l   d2,d0
  329.         move.b  (a2,d5.w),(a0)+
  330.         add.l   d3,d1
  331.         move.b    (a2,d5.w),(a0)+    ; I know this is crap but spare me the comments
  332.         subq.l  #2,d7
  333. l.skips2    move.l  a2,d4
  334.         lea     $1000(a1),a1    ; catch 22
  335.         move.l  a0,a3
  336.         add.l   d7,a3
  337.         move.l  d7,d5
  338.         and.b   #~7,d5
  339.         move.l  a0,a4
  340.         add.l   d5,a4
  341.         eor.w   d0,d1           ; swap fraction parts for addx
  342.         eor.w   d2,d3
  343.         eor.w   d1,d0
  344.         eor.w   d3,d2
  345.         eor.w   d0,d1
  346.         eor.w   d2,d3
  347.         swap    d0
  348.         swap    d1
  349.         swap    d2
  350.         swap    d3
  351.         lsl.w   #6,d1
  352.         lsl.w   #6,d3
  353.         move.w  #$ffc0,d6
  354.         move.w  #$f03f,d7
  355.         lsr.w   #3,d5
  356.         beq.b   l.skip_loop22
  357.         sub.w   d2,d0
  358.         add.l   d2,d0           ; setup the X flag
  359. l.loop22    or.w    d6,d0        ; Not really and exercise in optimizing
  360.         or.w    d7,d1        ; but I guess it's faster than 1x1 for 030
  361.         and.w   d1,d0        ; where this low detail business is needed.
  362.         addx.l  d3,d1
  363.         move.b  (a1,d0.w),d4
  364.         addx.l  d2,d0
  365.         move.l  d4,a2
  366.         move.w  (a2),d5
  367.         or.w    d6,d0
  368.         move.b    (a2),d5
  369.         or.w    d7,d1
  370.         and.w   d1,d0
  371.         swap    d5
  372.         addx.l  d3,d1
  373.         move.b  (a1,d0.w),d4
  374.         addx.l  d2,d0
  375.         move.l  d4,a2
  376.         move.w  (a2),d5
  377.         or.w    d6,d0
  378.         move.b    (a2),d5
  379.         or.w    d7,d1
  380.         and.w   d1,d0
  381.         move.l    d5,(a0)+
  382.         addx.l  d3,d1
  383.         move.b  (a1,d0.w),d4
  384.         addx.l  d2,d0
  385.         move.l  d4,a2
  386.         move.w  (a2),d5
  387.         or.w    d6,d0
  388.         move.b    (a2),d5
  389.         or.w    d7,d1
  390.         and.w   d1,d0
  391.         swap    d5
  392.         addx.l  d3,d1
  393.         move.b  (a1,d0.w),d4
  394.         addx.l  d2,d0
  395.         move.l  d4,a2
  396.         move.w  (a2),d5
  397.         move.b    (a2),d5
  398.         move.l  d5,(a0)+
  399.         cmp.l   a0,a4
  400.         bne.b   l.loop22
  401. l.skip_loop22
  402.         sub.w   d2,d0
  403.         add.l   d2,d0
  404.  
  405.         bra.b   l.loop_end22
  406. l.loop32      or.w    d6,d0
  407.         or.w    d7,d1
  408.         and.w   d1,d0
  409.         addx.l  d3,d1
  410.         move.b  (a1,d0.w),d4
  411.         addx.l  d2,d0
  412.         move.l  d4,a2
  413.         move.b  (a2),(a0)+
  414.         move.b    (a2),(a0)+
  415. l.loop_end22
  416.         cmp.l   a0,a3
  417.         bne.b   l.loop32
  418. l.end22        movem.l (sp)+,d2-d7/a2-a4
  419.         rts
  420.  
  421. ;-----------------------------------------------------------------------
  422.         cnop    0,4
  423.  
  424. _R_DrawTranslatedColumnLow
  425. @R_DrawTranslatedColumnLow
  426.         movem.l d2-d4/d6-d7/a2/a3,-(sp)
  427.  
  428.         move.l  _dc_yh(a4),d7    ; count = _dc_yh - _dc_yl
  429.         move.l  _dc_yl(a4),d0
  430.         sub.l   d0,d7
  431.         bmi.w   l.end3
  432.  
  433.         move.l  _dc_x(a4),d1    ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  434.         movea.l    _ylookup2(a4),a0 ;     = ylookup2[_dc_yl] + _dc_x
  435.         add.l    d1,d1
  436.         move.l  (a0,d0.l*4),a0
  437. ;;        movea.l    _columnofs(a4),a1
  438. ;;        add.l   (a1,d1.l*4),a0
  439.         adda.l    d1,a0            ; new
  440.  
  441.         move.l    _dc_translation(a4),d2
  442.         move.l  _dc_colormap(a4),d4
  443.         move.l  _dc_source(a4),a1
  444.  
  445.         move.l  _dc_iscale(a4),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  446.         sub.l   _centery(a4),d0
  447.         muls.l  d1,d0
  448.         add.l   _dc_texturemid(a4),d0
  449.  
  450.         moveq   #$7f,d3
  451. sw42_3        lea     (SCREENWIDTH*4).w,a3
  452.  
  453. ; d7: cnt >> 2
  454. ; a0: chunky
  455. ; a1: texture
  456. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  457. ; d1: dfrac (.......................................)
  458. ; d3: $7f
  459. ; d4: light table aligned to 256 byte boundary
  460. ; d2: translation table aligned to 256 byte boundary
  461. ; a3: SCREENWIDTH
  462.  
  463.         move.l  d7,d6
  464.         and.w   #3,d6
  465.  
  466.         swap    d0              ; swap decimals and fraction
  467.         swap    d1
  468.  
  469.         add.w   l.width_tab3(pc,d6.w*2),a0
  470.         lsr.w   #2,d7
  471.         move.w  l.tmap_tab3(pc,d6.w*2),d6
  472.  
  473.         and.w   d3,d0
  474.         sub.w   d1,d0
  475.         add.l   d1,d0           ; setup the X flag
  476.  
  477.         jmp     l.loop3(pc,d6.w)
  478.  
  479.         cnop    0,4
  480. l.width_tab3
  481. swm30_3        dc.w    -3*SCREENWIDTH
  482. swm20_3        dc.w    -2*SCREENWIDTH
  483. swm10_3        dc.w    -1*SCREENWIDTH
  484.         dc.w    0
  485. l.tmap_tab3
  486.         dc.w    l.03-l.loop3
  487.         dc.w    l.13-l.loop3
  488.         dc.w    l.23-l.loop3
  489.         dc.w    l.33-l.loop3
  490. l.loop3
  491. l.33
  492.         move.b  (a1,d0.w),d2
  493.         move.l    d2,a2
  494.         addx.l  d1,d0
  495.         move.b    (a2),d4
  496.         move.l  d4,a2
  497.         and.w   d3,d0
  498.         move.w    (a2),d6
  499.         move.b  (a2),d6
  500.         move.w    d6,(a0)
  501. l.23
  502.         move.b  (a1,d0.w),d2
  503.         move.l    d2,a2
  504.         addx.l  d1,d0
  505.         move.b    (a2),d4
  506.         move.l  d4,a2
  507.         and.w   d3,d0
  508.         move.w    (a2),d6
  509.         move.b  (a2),d6
  510. sw12_3        move.w    d6,SCREENWIDTH(a0)
  511. l.13
  512.         move.b  (a1,d0.w),d2
  513.         move.l    d2,a2
  514.         addx.l  d1,d0
  515.         move.b    (a2),d4
  516.         move.l  d4,a2
  517.         and.w   d3,d0
  518.         move.w    (a2),d6
  519.         move.b    (a2),d6
  520. sw22_3        move.w  d6,SCREENWIDTH*2(a0)
  521. l.03
  522.         move.b  (a1,d0.w),d2
  523.         move.l    d2,a2
  524.         addx.l  d1,d0
  525.         move.b    (a2),d4
  526.         move.l  d4,a2
  527.         and.w   d3,d0
  528.         move.w    (a2),d6
  529.         move.b    (a2),d6
  530. sw32_3        move.b  d6,SCREENWIDTH*3(a0)
  531.  
  532.         add.l   a3,a0
  533. l.loop_end3
  534.         dbf     d7,l.loop3
  535. l.end3
  536.         movem.l (sp)+,d2-d4/d6-d7/a2/a3
  537.         rts
  538.  
  539. ;-----------------------------------------------------------------------
  540.         cnop    0,4
  541.  
  542. _R_DrawFuzzColumnLow
  543. @R_DrawFuzzColumnLow
  544.         movem.l d4/d6-d7/a2/a3,-(sp)
  545.  
  546.         move.l    _viewheight(a4),d1
  547.         subq.l    #1,d1
  548.         move.l  _dc_yh(a4),d7    ; count = _dc_yh - _dc_yl
  549.         cmp.l    d1,d7
  550.         bne.b    l.skip_yh4
  551.         subq.l    #1,d1
  552.         move.l    d1,d7
  553. l.skip_yh4
  554.         move.l  _dc_yl(a4),d0
  555.         bne.b    l.skip_yl4
  556.         moveq    #1,d0
  557. l.skip_yl4
  558.         sub.l   d0,d7
  559.         bmi.w   l.end4
  560.  
  561.         move.l  _dc_x(a4),d1    ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  562.         movea.l    _ylookup2(a4),a0 ;     = ylookup2[_dc_yl] + _dc_x
  563.         add.l    d1,d1
  564.         move.l  (a0,d0.l*4),a0
  565.         adda.l    d1,a0
  566.  
  567.         move.l  _colormaps(a4),d4
  568.         add.l    #6*256,d4
  569.  
  570.         movea.l    _fuzzoffset(a4),a1
  571.         move.l    _fuzzpos(a4),d0    ; bring it down 
  572. l.pos_loop4    sub.l    _SCREENHEIGHT(a4),d0
  573.         bpl    l.pos_loop4
  574.         add.l    _SCREENHEIGHT(a4),d0
  575.         add.l    d0,a1
  576.  
  577. sw42_4        lea     (SCREENWIDTH*4).w,a3
  578.  
  579. ; d7: cnt >> 2
  580. ; a0: chunky
  581. ; a1: fuzzoffset
  582. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  583. ; d1: dfrac (.......................................)
  584. ; d3: $7f
  585. ; d4: light table aligned to 256 byte boundary
  586. ; a3: SCREENWIDTH
  587.  
  588.         move.l  d7,d6
  589.         and.w   #3,d6
  590.  
  591.         add.w   l.width_tab4(pc,d6.w*2),a0
  592.         lsr.w   #2,d7
  593.         move.w  l.tmap_tab4(pc,d6.w*2),d6
  594.  
  595.         jmp     l.loop4(pc,d6.w)
  596.  
  597.         cnop    0,4
  598. l.width_tab4
  599. swm30_4        dc.w    -3*SCREENWIDTH
  600. swm20_4        dc.w    -2*SCREENWIDTH
  601. swm10_4        dc.w    -1*SCREENWIDTH
  602.         dc.w    0
  603. l.tmap_tab4
  604.         dc.w    l.04-l.loop4
  605.         dc.w    l.14-l.loop4
  606.         dc.w    l.24-l.loop4
  607.         dc.w    l.34-l.loop4
  608. l.loop4
  609. l.34        move.l    a0,a2            ; This is essentially
  610.         add.l    (a1)+,a2        ; just moving memory around.
  611.         move.b    (a2),d4
  612.         move.l    d4,a2            
  613.         move.w    (a2),d6
  614.         move.b    (a2),d6
  615.         move.w    d6,(a0)        
  616. l.24
  617. sw12_4        lea    SCREENWIDTH(a0),a2    
  618.         add.l    (a1)+,a2        
  619.         move.b    (a2),d4            
  620.         move.l    d4,a2
  621.         move.w    (a2),d6
  622.         move.b    (a2),d6
  623. sw12_4a        move.w    d6,SCREENWIDTH(a0)
  624. l.14
  625. sw22_4        lea    2*SCREENWIDTH(a0),a2
  626.         add.l    (a1)+,a2
  627.         move.b    (a2),d4
  628.         move.l    d4,a2
  629.         move.w    (a2),d6
  630.         move.b    (a2),d6
  631. sw22_4a        move.w    d6,2*SCREENWIDTH(a0)
  632. l.04
  633. sw32_4        lea    3*SCREENWIDTH(a0),a2
  634.         add.l    (a1)+,a2
  635.         move.b    (a2),d4
  636.         move.l    d4,a2
  637.         move.w    (a2),d6
  638.         move.b    (a2),d6
  639. sw32_4a        move.w    d6,3*SCREENWIDTH(a0)
  640.  
  641.         add.l   a3,a0
  642. l.loop_end4
  643.         dbf    d7,l.loop4
  644.         sub.l    _fuzzoffset(a4),a1
  645.         move.l    a1,_fuzzpos
  646. l.end4
  647.         movem.l (sp)+,d4/d6-d7/a2/a3
  648.         rts
  649.  
  650. ;-----------------------------------------------------------------------
  651. ; high detail versions
  652.  
  653. ;-----------------------------------------------------------------------
  654.         cnop    0,4
  655.  
  656. _R_DrawFuzzColumn
  657. @R_DrawFuzzColumn
  658.         movem.l d4/d6-d7/a2/a3,-(sp)
  659.  
  660.         move.l    _viewheight(a4),d1
  661.         subq.l    #1,d1
  662.         move.l  _dc_yh(a4),d7    ; count = _dc_yh - _dc_yl
  663.         cmp.l    d1,d7
  664.         bne.b    l.skip_yh5
  665.         subq.l    #1,d1
  666.         move.l    d1,d7
  667. l.skip_yh5
  668.         move.l  _dc_yl(a4),d0
  669.         bne.b    l.skip_yl5
  670.         moveq    #1,d0
  671. l.skip_yl5
  672.         sub.l   d0,d7
  673.         bmi.w   l.end5
  674.  
  675.         movea.l    _ylookup2(a4),a0 ; dest = ylookup2[_dc_yl] + dc_x
  676.         move.l  (a0,d0.l*4),a0
  677.         adda.l    _dc_x(a4),a0
  678.  
  679.         move.l  _colormaps(a4),d4
  680.         add.l    #6*256,d4
  681.  
  682.         movea.l    _fuzzoffset(a4),a1
  683.         move.l    _fuzzpos(a4),d0
  684. l.pos_loop5    sub.l    _SCREENHEIGHT(a4),d0
  685.         bpl    l.pos_loop5
  686.         add.l    _SCREENHEIGHT(a4),d0
  687.         add.l    d0,a1
  688.  
  689. sw42_5        lea     (SCREENWIDTH*4).w,a3
  690.  
  691. ; d7: cnt >> 2
  692. ; a0: chunky
  693. ; a1: fuzzoffset
  694. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  695. ; d1: dfrac (.......................................)
  696. ; d3: $7f
  697. ; d4: light table aligned to 256 byte boundary
  698. ; a3: SCREENWIDTH
  699.  
  700.         move.l  d7,d6
  701.         and.w   #3,d6
  702.  
  703.         add.w   l.width_tab5(pc,d6.w*2),a0
  704.         lsr.w   #2,d7
  705.         move.w  l.tmap_tab5(pc,d6.w*2),d6
  706.  
  707.         jmp     l.loop5(pc,d6.w)
  708.  
  709.         cnop    0,4
  710. l.width_tab5
  711. swm30_5        dc.w    -3*SCREENWIDTH
  712. swm20_5        dc.w    -2*SCREENWIDTH
  713. swm10_5        dc.w    -1*SCREENWIDTH
  714.         dc.w    0
  715. l.tmap_tab5
  716.         dc.w    l.05-l.loop5
  717.         dc.w    l.15-l.loop5
  718.         dc.w    l.25-l.loop5
  719.         dc.w    l.35-l.loop5
  720. l.loop5
  721. l.35        move.l    a0,a2            ; This is essentially
  722.         add.l    (a1)+,a2        ; just moving memory around.
  723.         move.b    (a2),d4
  724.         move.l    d4,a2            ; Not 060 optimized but
  725.         move.b    (a2),(a0)        ; if you have hordes of
  726. l.25
  727. sw12_5        lea    SCREENWIDTH(a0),a2    ; invisible monsters which
  728.         add.l    (a1)+,a2        ; slow down the game too much,
  729.         move.b    (a2),d4            ; do tell me.
  730.         move.l    d4,a2
  731. sw12_5a        move.b    (a2),SCREENWIDTH(a0)
  732. l.15
  733. sw22_5        lea    2*SCREENWIDTH(a0),a2
  734.         add.l    (a1)+,a2
  735.         move.b    (a2),d4
  736.         move.l    d4,a2
  737. sw22_5a        move.b    (a2),2*SCREENWIDTH(a0)
  738. l.05
  739. sw32_5        lea    3*SCREENWIDTH(a0),a2
  740.         add.l    (a1)+,a2
  741.         move.b    (a2),d4
  742.         move.l    d4,a2
  743. sw32_5a        move.b    (a2),3*SCREENWIDTH(a0)
  744.  
  745.         add.l   a3,a0
  746. l.loop_end5
  747.         dbf    d7,l.loop5
  748.         sub.l    _fuzzoffset(a4),a1
  749.         move.l    a1,_fuzzpos
  750. l.end5
  751.         movem.l (sp)+,d4/d6-d7/a2/a3
  752.         rts
  753.  
  754. ;-----------------------------------------------------------------------
  755.         cnop    0,4
  756.  
  757. _R_DrawTranslatedColumn                    ; no 060 version :(
  758. @R_DrawTranslatedColumn
  759.         movem.l d2-d4/d6-d7/a2/a3,-(sp)
  760.  
  761.         move.l  _dc_yh(a4),d7    ; count = _dc_yh - _dc_yl
  762.         move.l  _dc_yl(a4),d0
  763.         sub.l   d0,d7
  764.         bmi.w   l.end6
  765.  
  766. ;;        move.l  _dc_x(a4),d1    ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  767.         movea.l    _ylookup2(a4),a0 ;     = ylookup2[_dc_yl] + _dc_x
  768.         move.l  (a0,d0.l*4),a0
  769. ;;        movea.l    _columnofs(a4),a1
  770. ;;        add.l   (a1,d1.l*4),a0
  771.         adda.l    _dc_x(a4),a0    ; new
  772.  
  773.         move.l    _dc_translation(a4),d2
  774.         move.l  _dc_colormap(a4),d4
  775.         move.l  _dc_source(a4),a1
  776.  
  777.         move.l  _dc_iscale(a4),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  778.         sub.l   _centery(a4),d0
  779.         muls.l  d1,d0
  780.         add.l   _dc_texturemid(a4),d0
  781.  
  782.         moveq   #$7f,d3
  783. sw42_6        lea     (SCREENWIDTH*4).w,a3
  784.  
  785. ; d7: cnt >> 2
  786. ; a0: chunky
  787. ; a1: texture
  788. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  789. ; d1: dfrac (.......................................)
  790. ; d3: $7f
  791. ; d4: light table aligned to 256 byte boundary
  792. ; d2: translation table aligned to 256 byte boundary
  793. ; a3: SCREENWIDTH
  794.  
  795.         move.l  d7,d6
  796.         and.w   #3,d6
  797.  
  798.         swap    d0              ; swap decimals and fraction
  799.         swap    d1
  800.  
  801.         add.w   l.width_tab6(pc,d6.w*2),a0
  802.         lsr.w   #2,d7
  803.         move.w  l.tmap_tab6(pc,d6.w*2),d6
  804.  
  805.         and.w   d3,d0
  806.         sub.w   d1,d0
  807.         add.l   d1,d0           ; setup the X flag
  808.  
  809.         jmp     l.loop6(pc,d6.w)
  810.  
  811.         cnop    0,4
  812. l.width_tab6
  813. swm30_6        dc.w    -3*SCREENWIDTH
  814. swm20_6        dc.w    -2*SCREENWIDTH
  815. swm10_6        dc.w    -1*SCREENWIDTH
  816.         dc.w    0
  817. l.tmap_tab6
  818.         dc.w    l.06-l.loop6
  819.         dc.w    l.16-l.loop6
  820.         dc.w    l.26-l.loop6
  821.         dc.w    l.36-l.loop6
  822. l.loop6
  823. l.36
  824.         move.b  (a1,d0.w),d2
  825.         move.l    d2,a2
  826.         addx.l  d1,d0
  827.         move.b    (a2),d4
  828.         and.w   d3,d0
  829.         move.l  d4,a2
  830.         move.b  (a2),(a0)
  831. l.26
  832.         move.b  (a1,d0.w),d2
  833.         move.l    d2,a2
  834.         addx.l  d1,d0
  835.         move.b    (a2),d4
  836.         and.w   d3,d0
  837.         move.l  d4,a2
  838. sw12_6        move.b  (a2),SCREENWIDTH(a0)
  839. l.16
  840.         move.b  (a1,d0.w),d2
  841.         move.l    d2,a2
  842.         addx.l  d1,d0
  843.         move.b    (a2),d4
  844.         and.w   d3,d0
  845.         move.l  d4,a2
  846. sw22_6        move.b  (a2),SCREENWIDTH*2(a0)
  847. l.06
  848.         move.b  (a1,d0.w),d2
  849.         move.l    d2,a2
  850.         addx.l  d1,d0
  851.         move.b    (a2),d4
  852.         and.w   d3,d0
  853.         move.l  d4,a2
  854. sw32_6        move.b  (a2),SCREENWIDTH*3(a0)
  855.  
  856.         add.l   a3,a0
  857. l.loop_end6
  858.         dbf     d7,l.loop6
  859. l.end6
  860.         movem.l (sp)+,d2-d4/d6-d7/a2/a3
  861.         rts
  862.  
  863. ;-----------------------------------------------------------------------
  864.         cnop    0,4
  865.  
  866. ; routine from j.selck@flensburg.netsurf.de   (Aki's 040 routine is faster)
  867.  
  868. ;_R_DrawColumn_030
  869. ;@R_DrawColumn_030
  870. ;        movem.l    d3-d7/a2-a5,-(sp)
  871. ;        move.l    _dc_yl(a4),d0
  872. ;        move.l    _dc_yh(a4),d7
  873. ;        sub.l    d0,d7
  874. ;        bmi.b    1$
  875. ;        move.l    _dc_x(a4),d1
  876. ;        movea.l    _columnofs(a4),a5
  877. ;        lea    (a5,d1.l*4),a1
  878. ;        movea.l    _ylookup(a4),a5
  879. ;        movea.l    (a5,d0.l*4),a2
  880. ;        adda.l    (a1),a2
  881. ;        move.l    _dc_iscale(a4),d6
  882. ;        sub.l    _centery(a4),d0
  883. ;        muls.l    d6,d0
  884. ;        move.l    _dc_texturemid(a4),d5
  885. ;        add.l    d0,d5
  886. ;        movea.l    _dc_source(a4),a3
  887. ;        movea.l    _dc_colormap(a4),a4
  888. ;        moveq    #127,d4
  889. ;        move.l    _SCREENWIDTH(a4),d3
  890. ;        moveq    #0,d1        ; ensure high bits of d1 are clear
  891. ;        add.w    d6,d5        ; frac += fracstep (also sets X flag)
  892. ;        swap    d5        ; swap(frac)
  893. ;        swap    d6        ; swap(fracstep)
  894. ;        and.w    d4,d5        ; (frac>>16)&127
  895. ;2$        move.b    (a3,d5.w),d1    ; dc_source[(frac>>FRACBITS)&127]
  896. ;        move.b    (a4,d1.w),(a2)    ; *dest = dc_colormap[d1]
  897. ;        addx.l    d6,d5        ; swap(frac += fracstep), use & set X
  898. ;        adda.l    d3,a2        ; dest += SCREENWIDTH
  899. ;        and.w    d4,d5        ; (frac>>16)&127
  900. ;        dbra    d7,2$
  901. ;1$        movem.l    (sp)+,d3-d7/a2-a5
  902. ;        rts
  903.  
  904. ;-----------------------------------------------------------------------
  905.         cnop    0,4
  906.  
  907. _R_DrawColumn_060
  908. @R_DrawColumn_060
  909.         movem.l d2-d3/d5-d7/a2/a3,-(sp)
  910.  
  911.         move.l  (_dc_yh),d7     ; count = _dc_yh - _dc_yl
  912.         move.l  (_dc_yl),d0
  913.         sub.l   d0,d7
  914.         bmi.w   l.end7
  915.  
  916. ;;        move.l  (_dc_x),d1      ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  917.         movea.l    (_ylookup2),a0    ;      = ylookup2[_dc_yl] + _dc_x
  918.         move.l  (a0,d0.l*4),a0
  919. ;;        movea.l    (_columnofs),a1
  920. ;;        add.l   (a1,d1.l*4),a0
  921.         adda.l    (_dc_x),a0    ; new
  922.  
  923.         move.l  (_dc_colormap),a2
  924.         move.l  (_dc_source),a1
  925.  
  926.         move.l  (_dc_iscale),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  927.         sub.l   (_centery),d0
  928.         muls.l  d1,d0
  929.         add.l   (_dc_texturemid),d0
  930.  
  931.         moveq   #$7f,d3
  932.         move.l  (_SCREENWIDTH),a3
  933.  
  934.         move.l  d7,d6           ; Do the leftover iterations in
  935.         and.w   #3,d6           ; this loop.
  936.         addq.w    #1,d6
  937. l.skip_loop7
  938.         move.l  d0,d5
  939.         swap    d5
  940.         and.l   d3,d5
  941.         move.b  (a1,d5.w),d5
  942.         add.l   d1,d0
  943.         move.b  (a2,d5.w),(a0)
  944.         add.l   a3,a0
  945.         subq.w  #1,d6
  946.         bne.b   l.skip_loop7
  947. ; d7: cnt >> 2
  948. ; a0: chunky
  949. ; a1: texture
  950. ; a2: light_table
  951. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  952. ; d1: dfrac*2   (.......................................)
  953. ; d2: frac+dfrac(.......................................)
  954. ; d3: $7f
  955. ; a3: SCREENWIDTH
  956. .skip7
  957.         lsr.l   #2,d7
  958.         subq.l    #1,d7
  959.         bmi.b    l.end7
  960.  
  961.         add.l   a3,a3
  962.  
  963.         move.l  d0,d2
  964.         add.l   a3,a3
  965.         add.l   d1,d2
  966.         add.l   d1,d1
  967.  
  968.         eor.w   d0,d2           ; swap the fraction part for addx
  969.         eor.w   d2,d0           ; assuming 16.16 fixed point
  970.         eor.w   d0,d2
  971.  
  972.         swap    d0              ; swap decimals and fraction
  973.         swap    d1
  974.         swap    d2
  975.  
  976.         moveq   #0,d5
  977.         and.w   d3,d2
  978.         and.w   d3,d0
  979.  
  980.         sub.w   d1,d0
  981.         add.l   d1,d0           ; setup the X flag
  982.  
  983.         move.b  (a1,d2.w),d5
  984. l.loop7
  985.         ; This should be reasonably scheduled for
  986.         ; m68060. It should perform well on other processors
  987.         ; too. That AGU stall still bothers me though.
  988.  
  989.         move.b  (a1,d0.w),d6        ; stall + pOEP but allows sOEP
  990.         addx.l  d1,d2               ; pOEP only
  991.         move.b  (a2,d5.l),d5        ; pOEP but allows sOEP
  992.         and.w   d3,d2               ; sOEP
  993.         move.b  (a2,d6.l),d6        ; pOEP but allows sOEP
  994. sw12_7        move.b  d5,SCREENWIDTH(a0)  ; sOEP
  995.         addx.l  d1,d0               ; pOEP only
  996.         move.b  (a1,d2.w),d5        ; pOEP but allows sOEP
  997.         and.w   d3,d0               ; sOEP
  998.         move.b  d6,(a0)             ; pOEP
  999.                         ; = ~4 cycles/pixel
  1000.                         ; + cache misses
  1001.  
  1002.         ; The vertical writes are the true timehog of the loop
  1003.         ; because of the characteristics of the copyback cache
  1004.         ; operation.
  1005.         
  1006.         ; Better mark the chunky buffer as write through
  1007.         ; with the MMU and have all the horizontal writes
  1008.         ; be longs aligned to longword boundary.
  1009.  
  1010.         move.b  (a1,d0.w),d6
  1011.         addx.l  d1,d2
  1012.         move.b  (a2,d5.l),d5
  1013.         and.w   d3,d2
  1014.         move.b  (a2,d6.l),d6
  1015. sw32_7        move.b  d5,SCREENWIDTH*3(a0)
  1016.         addx.l  d1,d0
  1017.         move.b  (a1,d2.w),d5
  1018.         and.w   d3,d0
  1019. sw22_7        move.b  d6,SCREENWIDTH*2(a0)
  1020.  
  1021.         add.l   a3,a0
  1022. l.loop_end7
  1023.         dbf     d7,l.loop7
  1024.  
  1025.         ; it's faster to divide it to two lines on 060
  1026.         ; and shouldn't be slower on 040.
  1027.  
  1028. ;        move.b  (a1,d0.w),d6    ; new
  1029. ;        move.b  (a2,d6.l),d6    ; new
  1030. ;        move.b  d6,(a0)     ; new
  1031.  
  1032. l.end7
  1033.         movem.l (sp)+,d2-d3/d5-d7/a2/a3
  1034.         rts
  1035.  
  1036. ;-----------------------------------------------------------------------
  1037.         cnop    0,4
  1038.  
  1039. ; 040 version
  1040.  
  1041. _R_DrawColumn_040
  1042. @R_DrawColumn_040
  1043.         movem.l d3-d4/d6-d7/a2/a3,-(sp)
  1044.  
  1045.         move.l  _dc_yh(a4),d7     ; count = _dc_yh - _dc_yl
  1046.         move.l  _dc_yl(a4),d0
  1047.         sub.l   d0,d7
  1048.         bmi.w   l.end8
  1049.  
  1050.         movea.l    _ylookup2(a4),a0  ; dest = ylookup2[_dc_yl] + _dc_x
  1051.         move.l  (a0,d0.l*4),a0
  1052.         adda.l    _dc_x(a4),a0
  1053.  
  1054.         move.l  _dc_colormap(a4),d4
  1055.         move.l  _dc_source(a4),a1
  1056.  
  1057.         move.l  _dc_iscale(a4),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  1058.         sub.l   _centery(a4),d0
  1059.         muls.l  d1,d0
  1060.         add.l   _dc_texturemid(a4),d0
  1061.  
  1062.         moveq   #$7f,d3
  1063. sw42_8        lea     (SCREENWIDTH*4).w,a3
  1064.  
  1065. ; d7: cnt >> 2
  1066. ; a0: chunky
  1067. ; a1: texture
  1068. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  1069. ; d1: dfrac (.......................................)
  1070. ; d3: $7f
  1071. ; d4: light table aligned to 256 byte boundary
  1072. ; a3: SCREENWIDTH
  1073.  
  1074.         move.l  d7,d6
  1075.         and.w   #3,d6
  1076.  
  1077.         swap    d0              ; swap decimals and fraction
  1078.         swap    d1
  1079.  
  1080.         adda.w    l.width_tab8(pc,d6.w*2),a0
  1081.         lsr.w   #2,d7
  1082.         move.w  l.tmap_tab8(pc,d6.w*2),d6
  1083.  
  1084.         and.w   d3,d0
  1085.         sub.w   d1,d0
  1086.         add.l   d1,d0           ; setup the X flag
  1087.  
  1088.         jmp    l.loop8(pc,d6.w)
  1089.  
  1090.         cnop    0,4
  1091. l.width_tab8
  1092. swm30_8        dc.w    -3*SCREENWIDTH
  1093. swm20_8        dc.w    -2*SCREENWIDTH
  1094. swm10_8        dc.w    -1*SCREENWIDTH
  1095.         dc.w    0
  1096. l.tmap_tab8
  1097.         dc.w    l.08-l.loop8
  1098.         dc.w    l.18-l.loop8
  1099.         dc.w    l.28-l.loop8
  1100.         dc.w    l.38-l.loop8
  1101. l.loop8
  1102. l.38
  1103.         move.b  (a1,d0.w),d4
  1104.         addx.l  d1,d0
  1105.         move.l  d4,a2
  1106.         and.w   d3,d0
  1107.         move.b  (a2),(a0)
  1108. l.28
  1109.         move.b  (a1,d0.w),d4
  1110.         addx.l  d1,d0
  1111.         move.l  d4,a2
  1112.         and.w   d3,d0
  1113. sw12_8        move.b  (a2),SCREENWIDTH(a0)
  1114. l.18
  1115.         move.b  (a1,d0.w),d4
  1116.         addx.l  d1,d0
  1117.         move.l  d4,a2
  1118.         and.w   d3,d0
  1119. sw22_8        move.b  (a2),SCREENWIDTH*2(a0)
  1120. l.08
  1121.         move.b  (a1,d0.w),d4
  1122.         addx.l  d1,d0
  1123.         move.l  d4,a2
  1124.         and.w   d3,d0
  1125. sw32_8        move.b  (a2),SCREENWIDTH*3(a0)
  1126.  
  1127.         adda.l    a3,a0
  1128. l.loop_end8
  1129.         dbf    d7,l.loop8
  1130. l.end8
  1131.         movem.l (sp)+,d3-d4/d6-d7/a2/a3
  1132.         rts
  1133.  
  1134. ;-----------------------------------------------------------------------
  1135. ; This faster version by Aki M Laukkanen <amlaukka@cc.helsinki.fi>
  1136.  
  1137.         cnop    0,4
  1138.  
  1139. _R_DrawSpan_060
  1140. @R_DrawSpan_060
  1141.         movem.l d2-d7/a2/a3,-(sp)
  1142.         move.l  (_ds_y),d0
  1143.         move.l  (_ds_x1),d1     ; dest = ylookup[_ds_y] + columnofs[_ds_x1]
  1144.         movea.l    (_ylookup2),a0    ;      = ylookup2[_ds_y] + _ds_x1
  1145.         move.l  (a0,d0.l*4),a0
  1146. ;;        movea.l    (_columnofs),a1
  1147. ;;        add.l   (a1,d1.l*4),a0
  1148.         adda.l    d1,a0            ; new
  1149.         move.l  (_ds_source),a1
  1150.         move.l  (_ds_colormap),a2
  1151.         move.l  (_ds_x2),d7     ; count = _ds_x2 - _ds_x1
  1152.         sub.l   d1,d7
  1153.         addq.l  #1,d7
  1154.         move.l  (_ds_xfrac),d0
  1155.         move.l  (_ds_yfrac),d1
  1156.         move.l  (_ds_xstep),d2
  1157.         move.l  (_ds_ystep),d3
  1158.         move.l  a0,d4
  1159.         btst    #0,d4
  1160.         beq.b   l.skipb9
  1161.         move.l  d0,d5           ; do the unaligned pixels
  1162.         move.l  d1,d6           ; so we can write to longword
  1163.         swap    d5              ; boundary in the main loop
  1164.         swap    d6
  1165.         and.w   #$3f,d5
  1166.         and.w   #$3f,d6
  1167.         lsl.w   #6,d6
  1168.         or.w    d5,d6
  1169.         move.b  (a1,d6.w),d5
  1170.         add.l   d2,d0
  1171.         move.b  (a2,d5.w),(a0)+
  1172.         add.l   d3,d1
  1173.         move.l  a0,d4
  1174.         subq.l  #1,d7
  1175. l.skipb9    btst    #1,d4
  1176.         beq.b   l.skips9
  1177.         moveq   #2,d4
  1178.         cmp.l   d4,d7
  1179.         bls.b   l.skips9
  1180.         move.l  d0,d5           ; write two pixels
  1181.         move.l  d1,d6
  1182.         swap    d5
  1183.         swap    d6
  1184.         and.w   #$3f,d5
  1185.         and.w   #$3f,d6
  1186.         lsl.w   #6,d6
  1187.         or.w    d5,d6
  1188.         move.b  (a1,d6.w),d5
  1189.         move.w  (a2,d5.w),d4
  1190.         add.l   d2,d0
  1191.         add.l   d3,d1
  1192.         move.l  d0,d5
  1193.         move.l  d1,d6
  1194.         swap    d5
  1195.         swap    d6
  1196.         and.w   #$3f,d5
  1197.         and.w   #$3f,d6
  1198.         lsl.w   #6,d6
  1199.         or.w    d5,d6
  1200.         move.b  (a1,d6.w),d5
  1201.         move.b  (a2,d5.w),d4
  1202.         add.l   d2,d0
  1203.         move.w  d4,(a0)+
  1204.         add.l   d3,d1
  1205.         subq.l  #2,d7
  1206. l.skips9    move.l  d7,d6           ; setup registers
  1207.         and.w   #3,d6
  1208.         move.l  d6,a3
  1209.         eor.w   d0,d1           ; swap fraction parts for addx
  1210.         eor.w   d2,d3
  1211.         eor.w   d1,d0
  1212.         eor.w   d3,d2
  1213.         eor.w   d0,d1
  1214.         eor.w   d2,d3
  1215.         swap    d0
  1216.         swap    d1
  1217.         swap    d2
  1218.         swap    d3
  1219.         lsl.w   #6,d1
  1220.         lsl.w   #6,d3
  1221.         moveq   #0,d6
  1222.         moveq   #0,d5
  1223.         sub.l   #$f000,a1
  1224.         lsr.l   #2,d7
  1225.         beq.w   l.skip_loop29
  1226.         subq.l  #1,d7
  1227.         sub.w   d3,d1
  1228.         add.l   d3,d1           ; setup the X flag
  1229.         or.w    #$ffc0,d0
  1230.         or.w    #$f03f,d1
  1231.         move.w  d0,d6
  1232.         and.w   d1,d6
  1233.         bra.b   l.start_loop29
  1234.         cnop    0,8
  1235. l.loop29    or.w    #$ffc0,d0       ; pOEP
  1236.         or.w    #$f03f,d1       ; sOEP
  1237.         move.b  (a2,d5.l),d4    ; pOEP but allows sOEP
  1238.         move.w  d0,d6           ; sOEP
  1239.         and.w   d1,d6           ; pOEP
  1240.         move.l  d4,(a0)+        ; sOEP
  1241. l.start_loop29
  1242.         addx.l  d2,d0           ; pOEP only
  1243.         addx.l  d3,d1           ; pOEP only
  1244.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  1245.         or.w    #$ffc0,d0       ; sOEP
  1246.         or.w    #$f03f,d1       ; pOEP
  1247.         move.w  d0,d6           ; sOEP
  1248.         move.w  (a2,d5.l),d4    ; pOEP but allows sOEP
  1249.         and.w   d1,d6           ; sOEP
  1250.         addx.l  d2,d0           ; pOEP only
  1251.         addx.l  d3,d1           ; pOEP only
  1252.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  1253.         or.w    #$ffc0,d0       ; sOEP
  1254.         or.w    #$f03f,d1       ; pOEP
  1255.         move.w  d0,d6           ; sOEP
  1256.         move.b  (a2,d5.l),d4    ; pOEP but allows sOEP
  1257.         and.w   d1,d6           ; sOEP
  1258.         addx.l  d2,d0           ; pOEP only
  1259.         addx.l  d3,d1           ; pOEP only
  1260.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  1261.         or.w    #$ffc0,d0       ; sOEP
  1262.         or.w    #$f03f,d1       ; pOEP
  1263.         move.w  d0,d6           ; sOEP
  1264.         swap    d4              ; pOEP only
  1265.         move.w  (a2,d5.l),d4    ; pOEP but allows sOEP
  1266.         and.w   d1,d6           ; sOEP
  1267.         addx.l  d2,d0           ; pOEP only
  1268.         addx.l  d3,d1           ; pOEP only
  1269.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  1270.         dbf     d7,l.loop29     ; pOEP only = 7.75 cycles/pixel
  1271.         move.b  (a2,d5.l),d4
  1272.         move.l  d4,(a0)+
  1273. l.skip_loop29
  1274.         sub.w   d3,d1
  1275.         add.l   d3,d1
  1276.         move.l  a3,d7
  1277.         bra.b   l.loop_end29
  1278. l.loop39      or.w    #$ffc0,d0
  1279.         or.w    #$f03f,d1
  1280.         move.w  d0,d6
  1281.         and.w   d1,d6
  1282.         addx.l  d2,d0
  1283.         addx.l  d3,d1
  1284.         move.b  (a1,d6.l),d5
  1285.         move.b  (a2,d5.l),(a0)+
  1286. l.loop_end29
  1287.         dbf     d7,l.loop39
  1288. l.end29       movem.l (sp)+,d2-d7/a2/a3
  1289.         rts
  1290.  
  1291.         cnop    0,4
  1292.  
  1293. ;-----------------------------------------------------------------------
  1294. ; 030/040 version
  1295.  
  1296. _R_DrawSpan_040
  1297. @R_DrawSpan_040
  1298.         movem.l d2-d7/a2-a4,-(sp)
  1299.         move.l  _ds_y(a4),d0
  1300.         move.l  _ds_x1(a4),d1    ; dest = ylookup[_ds_y] + columnofs[_ds_x1]
  1301.         movea.l    _ylookup2(a4),a0 ;     = ylookup2[_ds_y] + _ds_x1
  1302.         move.l  (a0,d0.l*4),a0
  1303. ;;        movea.l    _columnofs(a4),a1
  1304. ;;        add.l   (a1,d1.l*4),a0
  1305.         adda.l    d1,a0            ; new
  1306.         move.l  _ds_source(a4),a1
  1307.         move.l  _ds_colormap(a4),a2
  1308.         move.l  _ds_x2(a4),d7    ; count = _ds_x2 - _ds_x1
  1309.         sub.l   d1,d7
  1310.         addq.l  #1,d7
  1311.         move.l  _ds_xfrac(a4),d0
  1312.         move.l  _ds_yfrac(a4),d1
  1313.         move.l  _ds_xstep(a4),d2
  1314.         move.l  _ds_ystep(a4),d3
  1315.         move.l  a0,d4
  1316.         btst    #0,d4
  1317.         beq.b   l.skipb0
  1318.         move.l  d0,d5           ; do the unaligned pixels
  1319.         move.l  d1,d6           ; so we can write to longword
  1320.         swap    d5              ; boundary in the main loop
  1321.         swap    d6
  1322.         and.w   #$3f,d5
  1323.         and.w   #$3f,d6
  1324.         lsl.w   #6,d6
  1325.         or.w    d5,d6
  1326.         move.b  (a1,d6.w),d5
  1327.         add.l   d2,d0
  1328.         move.b  (a2,d5.w),(a0)+
  1329.         add.l   d3,d1
  1330.         move.l  a0,d4
  1331.         subq.l  #1,d7
  1332. l.skipb0    btst    #1,d4
  1333.         beq.b   l.skips0
  1334.         moveq   #2,d4
  1335.         cmp.l   d4,d7
  1336.         bls.b   l.skips0
  1337.         move.l  d0,d5           ; write two pixels
  1338.         move.l  d1,d6
  1339.         swap    d5
  1340.         swap    d6
  1341.         and.w   #$3f,d5
  1342.         and.w   #$3f,d6
  1343.         lsl.w   #6,d6
  1344.         or.w    d5,d6
  1345.         move.b  (a1,d6.w),d5
  1346.         move.w  (a2,d5.w),d4
  1347.         add.l   d2,d0
  1348.         add.l   d3,d1
  1349.         move.l  d0,d5
  1350.         move.l  d1,d6
  1351.         swap    d5
  1352.         swap    d6
  1353.         and.w   #$3f,d5
  1354.         and.w   #$3f,d6
  1355.         lsl.w   #6,d6
  1356.         or.w    d5,d6
  1357.         move.b  (a1,d6.w),d5
  1358.         move.b  (a2,d5.w),d4
  1359.         add.l   d2,d0
  1360.         move.w  d4,(a0)+
  1361.         add.l   d3,d1
  1362.         subq.l  #2,d7
  1363. l.skips0    move.l  a2,d4
  1364.         add.l   #$1000,a1       ; catch 22
  1365.         move.l  a0,a3
  1366.         add.l   d7,a3
  1367.         move.l  d7,d5
  1368.         and.b   #~3,d5
  1369.         move.l  a0,a4
  1370.         add.l   d5,a4
  1371.         eor.w   d0,d1           ; swap fraction parts for addx
  1372.         eor.w   d2,d3
  1373.         eor.w   d1,d0
  1374.         eor.w   d3,d2
  1375.         eor.w   d0,d1
  1376.         eor.w   d2,d3
  1377.         swap    d0
  1378.         swap    d1
  1379.         swap    d2
  1380.         swap    d3
  1381.         lsl.w   #6,d1
  1382.         lsl.w   #6,d3
  1383.         move.w  #$ffc0,d6
  1384.         move.w  #$f03f,d7
  1385.         lsr.w   #2,d5
  1386.         beq.b   l.skip_loop20
  1387.         sub.w   d2,d0
  1388.         add.l   d2,d0           ; setup the X flag
  1389. l.loop20    or.w    d6,d0
  1390.         or.w    d7,d1
  1391.         and.w   d1,d0
  1392.         addx.l  d3,d1
  1393.         move.b  (a1,d0.w),d4
  1394.         addx.l  d2,d0
  1395.         move.l  d4,a2
  1396.         move.w  (a2),d5
  1397.         or.w    d6,d0
  1398.         or.w    d7,d1
  1399.         and.w   d1,d0
  1400.         addx.l  d3,d1
  1401.         move.b  (a1,d0.w),d4
  1402.         addx.l  d2,d0
  1403.         move.l  d4,a2
  1404.         move.b  (a2),d5
  1405.         swap    d5
  1406.         or.w    d6,d0
  1407.         or.w    d7,d1
  1408.         and.w   d1,d0
  1409.         addx.l  d3,d1
  1410.         move.b  (a1,d0.w),d4
  1411.         addx.l  d2,d0
  1412.         move.l  d4,a2
  1413.         move.w  (a2),d5
  1414.         or.w    d6,d0
  1415.         or.w    d7,d1
  1416.         and.w   d1,d0
  1417.         addx.l  d3,d1
  1418.         move.b  (a1,d0.w),d4
  1419.         addx.l  d2,d0
  1420.         move.l  d4,a2
  1421.         move.b  (a2),d5
  1422.         move.l  d5,(a0)+
  1423.         cmp.l   a0,a4
  1424.         bne.b   l.loop20
  1425. l.skip_loop20
  1426.         sub.w   d2,d0
  1427.         add.l   d2,d0
  1428.  
  1429.         bra.b   l.loop_end20
  1430. l.loop30    or.w    d6,d0
  1431.         or.w    d7,d1
  1432.         and.w   d1,d0
  1433.         addx.l  d3,d1
  1434.         move.b  (a1,d0.w),d4
  1435.         addx.l  d2,d0
  1436.         move.l  d4,a2
  1437.         move.b  (a2),(a0)+
  1438. l.loop_end20
  1439.         cmp.l   a0,a3
  1440.         bne.b   l.loop30
  1441. l.end20        movem.l (sp)+,d2-d7/a2-a4
  1442.         rts
  1443.  
  1444. ;-----------------------------------------------------------------------
  1445. ; R_DrawMaskedColumn (in r_things.c) by Arto Huusko <arto.huusko@pp.qnet.fi>
  1446.  
  1447.         xref    _sprtopscreen    ;fixed_t
  1448.         xref    _spryscale    ;fixed_t
  1449.         xref    _mfloorclip    ;short*
  1450.         xref    _mceilingclip    ;short*
  1451.         xref    _colfunc
  1452.  
  1453. ;void R_DrawMaskedColumn (column_t* column)
  1454.  
  1455. ;column_t=post_t=
  1456. ;    byte    topdelta
  1457. ;    byte    length
  1458.  
  1459.         cnop    0,4
  1460.  
  1461. _R_DrawMaskedColumn:
  1462. @R_DrawMaskedColumn:
  1463.  
  1464.         cmp.b    #$FF,(a0)
  1465.         beq.w    .rd_Exit
  1466.  
  1467.         movem.l    d2-d6/a2/a3,-(sp)
  1468.  
  1469.         move.l    _dc_x(a4),d0
  1470.         moveq    #0,d3
  1471.         move.l    _mfloorclip(a4),a1
  1472.         move.w    (a1,d0.l*2),d3
  1473.         move.l    _mceilingclip(a4),a1
  1474.         move.w    (a1,d0.l*2),d4
  1475.         ext.l    d4
  1476.  
  1477.         move.l    _dc_texturemid(a4),d6    ;basetexturemid
  1478.         move.l    _spryscale(a4),d5
  1479.         move.l    _colfunc(a4),a3
  1480.  
  1481.         move.l    a0,a2        ;column talteen
  1482. .rd_Loop2:
  1483.         moveq    #0,d2
  1484.         move.b    (a2),d1
  1485.         extb.l    d1
  1486.         move.b    1(a2),d2
  1487.         muls.l    d5,d1
  1488.         mulu.l    d5,d2
  1489.         add.l    _sprtopscreen(a4),d1
  1490.         add.l    d1,d2
  1491.  
  1492.         add.l    #FRACUNIT-1,d1
  1493.         swap    d1        ;>>FRACBITS
  1494.         ext.l    d1
  1495.  
  1496.         subq.l    #1,d2
  1497.         swap    d2
  1498.         and.l    #$FFFF,d2
  1499.  
  1500.         cmp.w    d3,d2
  1501.         bmi.b    .rd_yhok
  1502.         move.l    d3,d2
  1503.         subq.l    #1,d2
  1504. .rd_yhok:
  1505.         cmp.l    d1,d4
  1506.         bmi.b    .rd_ylok
  1507.         move.l    d4,d1
  1508.         addq.l    #1,d1
  1509. .rd_ylok:
  1510.  
  1511.         move.l    d1,_dc_yl(a4)
  1512.         move.l    d2,_dc_yh(a4)
  1513.  
  1514.         cmp.w    d1,d2
  1515.         bmi.b    .rd_skip
  1516.  
  1517.         move.l    a2,_dc_source(a4)
  1518.         addq.l    #3,_dc_source(a4)
  1519.  
  1520.         move.l    d6,_dc_texturemid(a4)
  1521.         moveq    #0,d0
  1522.         move.b    (a2),d0
  1523.         swap    d0
  1524.         sub.l    d0,_dc_texturemid(a4)
  1525.         jsr    (a3)
  1526. .rd_skip:
  1527.         moveq    #4,d0
  1528.         add.b    1(a2),d0
  1529.         add.l    d0,a2
  1530.  
  1531.         cmp.b    #$FF,(a2)
  1532.         bne.b    .rd_Loop2
  1533.  
  1534.         move.l    d6,_dc_texturemid(a4)
  1535.  
  1536.         movem.l    (sp)+,d2-d6/a2/a3
  1537.  
  1538. .rd_Exit:
  1539.         rts
  1540.  
  1541.  
  1542. ;//
  1543. ;// R_DrawMaskedColumn
  1544. ;// Used for sprites and masked mid textures.
  1545. ;// Masked means: partly transparent, i.e. stored
  1546. ;//  in posts/runs of opaque pixels.
  1547. ;//
  1548. ;short*        mfloorclip;
  1549. ;short*        mceilingclip;
  1550. ;
  1551. ;fixed_t        spryscale;
  1552. ;fixed_t        sprtopscreen;
  1553. ;
  1554. ;void R_DrawMaskedColumn (column_t* column)
  1555. ;{
  1556. ;    int        topscreen;
  1557. ;    int     bottomscreen;
  1558. ;    fixed_t    basetexturemid;
  1559. ;    
  1560. ;    basetexturemid = dc_texturemid;
  1561. ;    
  1562. ;    for ( ; column->topdelta != 0xff ; ) 
  1563. ;    {
  1564. ;    // calculate unclipped screen coordinates
  1565. ;    //  for post
  1566. ;    topscreen = sprtopscreen + spryscale*column->topdelta;
  1567. ;    bottomscreen = topscreen + spryscale*column->length;
  1568. ;
  1569. ;    dc_yl = (topscreen+FRACUNIT-1)>>FRACBITS;
  1570. ;    dc_yh = (bottomscreen-1)>>FRACBITS;
  1571. ;        
  1572. ;    if (dc_yh >= mfloorclip[dc_x])
  1573. ;        dc_yh = mfloorclip[dc_x]-1;
  1574. ;    if (dc_yl <= mceilingclip[dc_x])
  1575. ;        dc_yl = mceilingclip[dc_x]+1;
  1576. ;
  1577. ;    if (dc_yl <= dc_yh)
  1578. ;    {
  1579. ;        dc_source = (byte *)column + 3;
  1580. ;        dc_texturemid = basetexturemid - (column->topdelta<<FRACBITS);
  1581. ;        // dc_source = (byte *)column + 3 - column->topdelta;
  1582. ;
  1583. ;        // Drawn by either R_DrawColumn
  1584. ;        //  or (SHADOW) R_DrawFuzzColumn.
  1585. ;        colfunc ();    
  1586. ;    }
  1587. ;    column = (column_t *)(  (byte *)column + column->length + 4);
  1588. ;    }
  1589. ;    
  1590. ;    dc_texturemid = basetexturemid;
  1591. ;}
  1592.  
  1593. ;-----------------------------------------------------------------------
  1594. ; V_DrawPatch (in v_video.c) by Arto Huusko <arto.huusko@pp.qnet.fi>
  1595.  
  1596.         xref    _screens    ;byte* screens[5]
  1597.  
  1598.         xref    @I_MarkRect
  1599.  
  1600.         STRUCTURE    patch,0
  1601.          WORD    width
  1602.          WORD    height
  1603.          WORD    leftoffset
  1604.          WORD    topoffset
  1605.          STRUCT    columnofs,9*4    ;nine ints
  1606.         LABEL    patch_size
  1607.  
  1608. ;width        equ    0
  1609. ;height        equ    2
  1610. ;leftoffset    equ    4
  1611. ;topoffset    equ    6
  1612. ;columnofs    equ    8
  1613. ;patch_size    equ    8+(9*4)
  1614.  
  1615. column_t
  1616.         STRUCTURE    column,0
  1617.          BYTE    topdelta
  1618.          BYTE    length
  1619.         LABEL    column_size
  1620.  
  1621. ;topdelta    equ    0
  1622. ;length        equ    1
  1623. ;column_size    equ    2
  1624.  
  1625.         cnop    0,4
  1626. _V_DrawPatch:
  1627. @V_DrawPatch:
  1628. _V_DrawPatchDirect:
  1629. @V_DrawPatchDirect:
  1630.         movem.l    d3-d6/a2/a3/a5,-(sp)
  1631.  
  1632.         move.l    d0,d3    ;x
  1633.         move.l    d1,d4    ;y.. scrn in (sp), patch in a0
  1634.  
  1635.         move.l    a0,a2    ;Store patch
  1636.         moveq    #0,d0
  1637.         move.w    topoffset(a2),d0
  1638.         rol.w    #8,d0    ;SWAPSHORT
  1639.         ext.l    d0
  1640.         sub.l    d0,d4
  1641.         moveq    #0,d0
  1642.         move.w    leftoffset(a2),d0
  1643.         rol.w    #8,d0    ;SWAPSHORT
  1644.         ext.l    d0
  1645.         sub.l    d0,d3
  1646.  
  1647.         move.l    32(sp),d6
  1648.         bne.b    .vd_ScrnOK
  1649.         move.l    d3,d0
  1650.         move.l    d4,d1
  1651.         moveq    #0,d5
  1652.         move.w    height(a2),d5
  1653.         rol.w    #8,d5
  1654.         move.l    d5,-(sp)
  1655.         move.w    width(a2),d5
  1656.         rol.w    #8,d5
  1657.         move.l    d5,-(sp)
  1658.         jsr    (@I_MarkRect)
  1659.         addq.l    #8,sp
  1660.  
  1661. .vd_ScrnOK:
  1662.         lea    _screens(a4),a0
  1663.         move.l    (a0,d6.l*4),d5
  1664. ;Peter... change here (quite obvious)
  1665.         muls.l    _SCREENWIDTH(a4),d4    ;y not needed further
  1666.         add.l    d3,d5    ;+x
  1667.         add.l    d4,d5    ;+y*SCREENWIDTH
  1668.  
  1669.         ;D3=x, D5=desttop,
  1670.         moveq    #0,d6
  1671.         move.w    width(a2),d6
  1672.         rol.w    #8,d6    ;SWAPSHORT
  1673.         ;D6=w
  1674.         subq.l    #1,d6    ;for ; col<w
  1675.         lea    columnofs(a2),a3    ;prepare for columnofs[col]
  1676.  
  1677. .vd_Loop:
  1678.         move.l    (a3)+,d0
  1679.         rol.w    #8,d0
  1680.         swap    d0
  1681.         rol.w    #8,d0        ;three instructions for SWAPLONG
  1682.         move.l    a2,a5        ;column=patch+
  1683.         add.l    d0,a5        ;... SWAPLONG(patch->columnofs[col])
  1684.  
  1685.         cmp.b    #$FF,(a5)
  1686.         beq.b    .vdl_Next    ;last column
  1687.  
  1688. .vdl_Loop:
  1689.         move.l    d5,a1        ;dest=desttop + 
  1690.  
  1691. ;... here are the other references to SCREENWIDTH
  1692. ;    lsl.l #8,x + lsl.l #6,x is equal to 256x+64x=320x
  1693.  
  1694.         moveq    #0,d0
  1695.         move.b    (a5),d0        ;column->topdelta*
  1696. ;;;        move.l    d0,d1    ;!
  1697. ;;;        lsl.l    #8,d0    ;!
  1698. ;;;        lsl.l    #6,d1    ;!
  1699. ;;;        add.l    d0,a1    ;!
  1700. ;;;        add.l    d1,a1    ;!
  1701.  
  1702.         muls.l    _SCREENWIDTH(a4),d0
  1703.         add.l    d0,a1
  1704.  
  1705.         move.b    1(a5),d0
  1706.         addq.l    #3,a5        ;source
  1707.         ;Would it be possible to use the code from DrawColumn functions by Aki
  1708.         ;here, too??
  1709. .vdl_DrawLoop:
  1710.         move.b    (a5)+,(a1)
  1711.         add.l    _SCREENWIDTH(a4),a1
  1712.         subq.b    #1,d0
  1713.         bne.b    .vdl_DrawLoop
  1714.  
  1715.         addq.l    #1,a5        ;bump to next column..
  1716.         ;bumped already by three and length, so one more. (column +=column->length+4)
  1717.  
  1718.         cmp.b    #$FF,(a5)
  1719.         bne.b    .vdl_Loop
  1720.  
  1721. .vdl_Next:
  1722.         addq.l    #1,d5
  1723.  
  1724.         dbf        d6,.vd_Loop
  1725. .vd_exit:
  1726.         movem.l    (sp)+,d3-d6/a2/a3/a5
  1727.  
  1728.         rts
  1729.  
  1730. ;void
  1731. ;V_DrawPatch
  1732. ;( int        x,
  1733. ;  int        y,
  1734. ;  int        scrn,
  1735. ;  patch_t*    patch ) 
  1736. ;{ 
  1737. ;
  1738. ;    int        count;
  1739. ;    int        col; 
  1740. ;    column_t*    column; 
  1741. ;    byte*    desttop;
  1742. ;    byte*    dest;
  1743. ;    byte*    source; 
  1744. ;    int        w; 
  1745. ;     
  1746. ;    y -= SWAPSHORT(patch->topoffset); 
  1747. ;    x -= SWAPSHORT(patch->leftoffset); 
  1748. ;    col = 0; 
  1749. ;    desttop = screens[scrn]+y*SCREENWIDTH+x; 
  1750. ;     
  1751. ;    w = SWAPSHORT(patch->width); 
  1752. ;
  1753. ;    for ( ; col<w ; x++, col++, desttop++)
  1754. ;    { 
  1755. ;    column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[col])); 
  1756. ;    // step through the posts in a column 
  1757. ;    while (column->topdelta != 0xff ) 
  1758. ;    { 
  1759. ;        source = (byte *)column + 3; 
  1760. ;        dest = desttop + column->topdelta*SCREENWIDTH; 
  1761. ;        count = column->length; 
  1762. ;             
  1763. ;        while (count--) 
  1764. ;        { 
  1765. ;        *dest = *source++; 
  1766. ;        dest += SCREENWIDTH; 
  1767. ;        } 
  1768. ;        column = (column_t *)(  (byte *)column + column->length 
  1769. ;                    + 4 ); 
  1770. ;    }
  1771. ;    }
  1772. ;    if (!scrn)
  1773. ;    I_MarkRect (x, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height)); 
  1774. ;
  1775. ;} 
  1776.  
  1777. ;***********************************************************************
  1778.  
  1779.         end
  1780.